package cn.itsource.langxun.controller;

import cn.itsource.langxun.util.AjaxResult;
import cn.itsource.langxun.util.RedisUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisController {
    /**
     * 设置值
     * @param key
     * @param value
     */
    @PostMapping("/redis")
    public AjaxResult set(@RequestParam("key") String key, @RequestParam("value") String value){
        try {
            RedisUtils.INSTANCE.set(key, value);
            return AjaxResult.li().setSuccess(true).setMessage("成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.li().setSuccess(false).setMessage("失败!");
        }
    }

    /**
     *
     * @param key
     * @return
     */
    @GetMapping("/redis")
    public String get(@RequestParam("key") String key){
        return RedisUtils.INSTANCE.get(key);
    }

}
